package com.hrm.action;

import com.hrm.action.annotation.Action;
import com.hrm.action.annotation.RequestPath;
import com.hrm.action.annotation.ResponsePath;
import com.hrm.dto.Envelope;
import com.hrm.entity.AdminEntity;
import com.hrm.service.AdminService;
import com.hrm.service.EmployeeService;
//import com.hrm.service.EmployerService;

import javax.servlet.http.HttpSession;

/**
 * Create by zekdot on 20-2-26.
 */
@Action
@RequestPath(path="/admin")
public class AdminAction {

    private AdminService adminService;
//
    private EmployeeService employeeService;
    public AdminAction(){
        adminService = new AdminService();
        employeeService = new EmployeeService();
    }
    @RequestPath(path="/login")
    public String login(HttpSession session,String id, String password){
        Envelope envelope = adminService.login(id,password);
        session.setAttribute("user",envelope.getObj());
        envelope.setObj(null);
        return envelope.toString();
    }

    @RequestPath(path = "/changePasswordPage")
    @ResponsePath(path = "/common/changePassword")
    public String changePasswordPage(){
        return "success";
    }

    @RequestPath(path = "/changePassword")
    public String changePassword(HttpSession session,String oriPassword,String newPassword){
        AdminEntity adminEntity = (AdminEntity) session.getAttribute("user");
        return adminService.changePassword(adminEntity.getId(),oriPassword,newPassword).toString();
    }

    /**
     * 更新雇主信息
     * @param id 雇主id
     * @param paramJson 参数
     * @return
     */
    @RequestPath(path = "/updateEmployer")
    public String updateEmployer(String id,String paramJson){
        return employeeService.updateInfo(id,paramJson).toString();
    }

    /**
     * 更新薪水
     * @param id
     * @param paramJson
     * @return
     */
    @RequestPath(path = "/updateSalary")
    public String updateSalary(String id,String year,String month,String paramJson){
        return employeeService.updateSalary(id,year,month,paramJson).toString();
    }
    @RequestPath(path = "/employeePage")
    @ResponsePath(path = "/admin/employee")
    public String employeePage(){
        return "success";
    }
}
